﻿@using NFine.Domain._03_Entity.Biz
@{
    ViewBag.Title = "WithDraw";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<style type="text/css">
    .table {
        width: 100%;
        margin-bottom: 20px;
    }

    .table thead tr {
        background: #F2F8FC;
    }

    .table tbody tr {
        background-color: white;
    }

    .table tr td, .table tr th {
        padding: 8px;
        border: 1px solid #ccc;
        border-top: 1px solid #ccc;
        text-align: center;
        line-height: 23px;
    }
</style>

<script>
    $(function () {
        initControl();
        getProperty();
    });
    function submitForm() {
        if (!$('#form1').formValid()) {
            return false;
        }
        $.submitForm({
            url: "/MemberManage/MemberWithdrawals/SubmitForm",
            param: $("#form1").formSerialize(),
            success: function () {
                $.currentWindow().$(".toolbar .operate").find('.close').click();
                $.currentWindow().$.reload();
            }
        })
    }

    function initControl() {
        $("#txt_BankType").on('change', function () {
            $('#txt_bank').val("");
            $('#txt_people').val("");
            $('#txt_bankCaid').val("");
            if ($(this).val() != '-1') {
                var $option = $(this).find('option:selected');
                $('#txt_bank').val($option.attr('data-bank'));
                $('#txt_people').val($option.attr('data-man'));
                $('#txt_bankCaid').val($option.attr('data-card'));
            }
        });
    }

    //获取供货商资产信息
    function getProperty() {
        $.ajax({
            url: "/MemberManage/MemberWithdrawals/GetProperty",
            success: function (result) {
                var data = eval('(' + result + ')');
                $('#userProperty').html(data.userProperty);
                userMoney = data.userProperty;
            }
        });
    }


    function isNull(str) {
        if (str == "") return true;
        var regu = "^[ ]+$";
        var re = new RegExp(regu);
        return re.test(str);
    }


    function submitForm() {

        if (!$('#form1').formValid()) {
            return false;
        }

        var userProperty = $('#userProperty').html();
        var money = $('#txt_money').val();
        var bankId = $('#txt_BankType').val();
        if (bankId == '-1') {
            alert("请选择银行卡！");
            return;
        }

        if (isNull(money)) {
            alert("请输入提现金额！");
            return;
        }

        if (!(/(^[1-9]\d*$)/.test(money)))
        {
            alert('提现金额必须为正整数');
            return false;
        }

        if (parseInt(money)<=0) {
            alert("提现金额必须为正数！");
            return;
        }

        var fmoney = parseFloat(money);
        var fuserProperty = parseFloat(userProperty);

        if (fmoney > fuserProperty) {
            alert("余额不足！");
            return;
        }

        if (parseInt(money)%100 != 0) {
            alert("提现金额必须为整百数！");
            return;
        }



        $.submitForm({
            url: "/MemberManage/MemberWithdrawals/Withdrawals",
            param: { money: money, bankId: bankId },
            success: function () {
                $.currentWindow().$(".toolbar .operate").find('.close').click();
                $.currentWindow().$.reload();
            }
        })
    }

</script>
<form id="form1">
    <div style="padding-top: 20px; margin-right: 30px;">
        <table class="form">
            <tr>
                <th class="formTitle" style="font-weight: bold; width: 120px;">账户现金余额(元)</th>
                <td class="formValue" style="font-weight: bold;" colspan="3">
                    <span id="userProperty">-</span>
                </td>
            </tr>
            <tr>
                <th class="formTitle">提现银行卡</th>
                <td class="formValue" colspan="3">
                    <select id="txt_BankType" class="form-control" style="width: 250px; margin-right: 10px">
                        <option value="-1" selected="selected">请选择提现银行卡</option>
                        @foreach (var entity in (List<UserBankEntity>)ViewData["bankList"])
                        {
                            <option value="@entity.F_Id" data-bank="@entity.F_OpeningBank" data-man="@entity.F_AccountName" data-card="@entity.F_Account">@entity.F_BankName</option>
                        }
                    </select>

                </td>
            </tr>
            <tr>
                <th class="formTitle">开户行</th>
                <td class="formValue" colspan="3">
                    <input id="txt_bank" type="text" class="form-control " placeholder="开户行" style="width: 250px; margin-right: 10px" readonly="readonly" />
                </td>
            </tr>
            <tr>
                <th class="formTitle">开户人</th>
                <td class="formValue" colspan="3">
                    <input id="txt_people" type="text" class="form-control " placeholder="开户人" style="width: 250px; margin-right: 10px" readonly="readonly" />
                </td>
            </tr>
            <tr>
                <th class="formTitle">卡号</th>
                <td class="formValue" colspan="3">
                    <input id="txt_bankCaid" type="text" class="form-control " placeholder="卡号" style="width: 250px; margin-right: 10px" readonly="readonly" />
                </td>
            </tr>
            <tr>
                <th class="formTitle">提现金额</th>
                <td class="formValue" colspan="3">
                    <input id="txt_money" type="number" class="form-control " placeholder="请输入提现金额(小于等于账户余额,整百数)" style="width: 250px; margin-right: 10px" />
                </td>
            </tr>

        </table>
    </div>




    
</form>
